home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / imagine / extras / tools / iiutilities / stagescale < prev    next >
Text File  |  1995-01-17  |  4KB  |  92 lines

  1. /*\
  2.  *
  3.  *  ARexx script to reduce or enlarge a stage by a set amount to decrease
  4.  *  rendering times. (Or so I am told:)
  5.  *
  6.  *  Usage: StageScale <stageFileName> <multiplier>
  7.  *    Using a 0.5 for <multiplier> will reduce the scene and objects
  8.  *    to half of its original size, and using 2 will double the size.
  9.  *
  10.  *  Notes:
  11.  *    Each object is given a line of its own in the output.  A "." is
  12.  *    displayed for each timeline bar that is modified.
  13.  *    If you reduce or enlarge a file too much you will hit Imagine's
  14.  *    limit and parts of objecs will start to dissapear or vanish
  15.  *    completely from the scene.  Make sure your scene fits in around
  16.  *    16,000 imagine units or so, you have to expetiment to find the
  17.  *    maximum size.
  18.  *
  19.  *  V1.0 Nov-22-94
  20.  *  IanSmith@moose.erie.net
  21.  *
  22. \*/
  23.  
  24. Numeric Digits 14                    /* Need at least 12 to handle 32 bits */
  25. Parse Arg FileName Change .
  26. If FileName="" Then Do
  27.  Say "Usage: StageScale <stageFileName> <multiplier>"
  28.  Say "       More help is in the header of this file."
  29.  Exit
  30. End
  31. If Exists(FileName)=0 Then Do
  32.  Say "I can't find "FileName"!"
  33.  Exit
  34. End
  35.  
  36. Temp="TestStage."||Date(D)||Time(S)                /* Create temp filename */
  37. Address Command 'Delete QUIET' FileName||".Old"    /* Erase backup file    */
  38. Call Open(Out,Temp,"W") Open(Con,"*","W")
  39. Call WriteCH(Con,"Multiplying '"FileName"' by" Change)
  40. Call Open(In,FileName,"R") ParseStaging(C2D(SubStr(ReadWrite(In,12),5,4)))
  41. Call Close(In) Close(Out) CLose(Con)
  42. Address Command 'Rename' FileName 'To' FileName||".Old"
  43. Address Command 'Rename' Temp 'To' FileName
  44. Say; Exit
  45.  
  46. ParseStaging: PROCEDURE EXPOSE Change          /* Recursive function       */
  47.  Parse Arg MaxSize
  48.  TotalSize=4
  49.  Do Until TotalSize>=MaxSize                   /* Read MaxSize Bytes       */
  50.   Name=ReadWrite(In,4)
  51.   Size=C2D(ReadWrite(In,4))
  52.   If Size//2=1 Then Size=Size+1                /* Add pad byte if needed   */
  53.   If Name="ISTG" | Name="SOBJ" Then Do
  54.    TotalSize=TotalSize+ParseStaging(Size)+8    /* Parse into these hunks   */
  55.    Iterate
  56.   End
  57.   TotalSize=TotalSize+Size+8                   /* Add SIZE and NAME length */
  58.  
  59.   If Name="NAME" Then Do
  60.    Call WriteCh(Con,'A'x||ReadWrite(In,Size)" ")
  61.   End; Else If Name="POS2" Then Do                 /* POZ2 = Position */
  62.    Call WriteCh(Con,"p")
  63.    Buffer=ReadCH(In,Size)
  64.    Call WriteCH(Out,Overlay(FToBin(BinToF(SubStr(Buffer,7,4))*Change)||FToBin(BinToF(SubStr(Buffer,11,4))*Change)||FToBin(BinToF(SubStr(Buffer,15,4))*Change),Buffer,7))
  65.   End; Else If Name="OSZ2" Then Do                /* OSZ2 = Size      */
  66.    Call WriteCh(Con,"s")
  67.    Buffer=ReadCH(In,Size)
  68.    Call WriteCH(Out,Overlay(FToBin(BinToF(SubStr(Buffer,7,4))*Change)||FToBin(BinToF(SubStr(Buffer,11,4))*Change)||FToBin(BinToF(SubStr(Buffer,15,4))*Change),Buffer,7))
  69.   End; Else Do
  70.    Call ReadWrite(In,Size)
  71.   End
  72.  End
  73. Return TotalSize
  74.  
  75. ReadWrite:                                  /* This reads staging data,  */
  76.  Parse Arg FileHandle , Bytes .             /* writes it to the new file */
  77.  RWBuffer=ReadCH(FileHandle, Bytes)         /* and returns the data.     */
  78.  Call WriteCH(Out,RWBuffer)
  79. Return RWBuffer
  80.  
  81. BinToF:                                     /* Convert from Imagine FP nums   */
  82.  Parse Arg ConvertFNum                      /* to something we can work with. */
  83. Return C2D(ConvertFNum)/65536
  84.  
  85. FToBin:
  86.  Parse Arg ConvertBNum                      /* Convert back to Imagine FP.  */
  87.  If ConvertBNum<0 Then                      /* D2C(2**31) is broken!        */
  88.   ConvertBNum=2**32+ConvertBNum*65536
  89.  Else
  90.   ConvertBNum=ConvertBNum*65536
  91. Return Right(D2C(ConvertBNum/65536%1),2,'00'x)||Right(D2C(ConvertBNum//65536%1),2,'00'x)
  92.